/**
 * 1.数组扩展运算符（...）
 */
console.log('============>1.数组扩展运算符（...）<============')
// 传统
function foo(a, b, c) {
    console.log('传统：', a, b, c);
}
foo(1);
// es6
function foo1(...arr) {
    console.log('es6: ', arr[0], arr[1], arr[2]);
}
foo1(2)

/**
 * 2.对象扩展
 */
 console.log('============>2.对象扩展运算符（...）<============')
 let obj = {
    title: 'WEB',
    author: 'Maple',
    sayHello() {
        console.log('say: ', 'Hello World!')
    }
}
console.log('对象: ', obj)
let {title, ...obj2} = obj;
console.log('对象扩展: ', title)
console.log('对象扩展: ', obj2)


/**
 * 3.扩展运算符常见案例
 */
console.log('============>3.扩展运算符常见案例<============')
let lowArr1 = [1, 2, 3];
// 浅拷贝
let lowArr2 = lowArr1;
console.log('lowArr2: ', lowArr2);
lowArr2.push(4);
console.log('lowArr1: ', lowArr1);
// 深拷贝
let deepArr1 = [2, 5, 8];
let deepArr2 = [...deepArr1];
console.log('deepArr2: ', deepArr2)
deepArr2.push(3);
console.log('deepArr1: ', deepArr1)

// 数组合并
console.log('============>数组合并<============')
let books = ['三国演义']
let books1 = ['西游记']
let books2 = ['水浒传']
// 传统
let booksnew = books.concat(books1, books2)
console.log('传统: ', booksnew)
// es6
let bookses6 = [...books, ...books1, ...books2]
console.log('es6: ', bookses6)

// rest使用，函数参数个数未知
function rest(a, ...arg) {
    console.log('a: ', a)
    for (const val of arg) {
        console.log('arg遍历：', val)
    }
}
rest(1, 2, 3, 4, 5, 6, 7);